/**
 * @file command_executor_debug.h
 * @brief 命令执行器调试宏定义和内存优化工具
 */

#ifndef COMMAND_EXECUTOR_DEBUG_H
#define COMMAND_EXECUTOR_DEBUG_H

// 🔧 调试输出的条件编译
#ifdef DEBUG_VERBOSE
#define DEBUG_PRINT(x) Serial.println(x)
#define DEBUG_PRINTF(format, ...) Serial.printf(format, __VA_ARGS__)
#else
#define DEBUG_PRINT(x) 
#define DEBUG_PRINTF(format, ...)
#endif

// 🔧 内存优化宏定义
#define MEMORY_OPTIMIZATION_ENABLED 1

#if MEMORY_OPTIMIZATION_ENABLED
  // 内存使用监控
  #define MEM_PRINT_FREE() Serial.printf("[MEM] 可用内存: %d bytes\n", ESP.getFreeHeap())
  #define MEM_CHECK_THRESHOLD(threshold) \
    if (ESP.getFreeHeap() < threshold) { \
      Serial.printf("[MEM] 警告: 内存不足 %d bytes\n", ESP.getFreeHeap()); \
    }
  
  // String预分配优化
  #define STRING_RESERVE(str, size) str.reserve(size)
  
  // JSON缓冲区大小常量
  #define JSON_SIZE_SMALL 192
  #define JSON_SIZE_MEDIUM 384
  #define JSON_SIZE_LARGE 768
#else
  #define MEM_PRINT_FREE()
  #define MEM_CHECK_THRESHOLD(threshold)
  #define STRING_RESERVE(str, size)
  #define JSON_SIZE_SMALL 256
  #define JSON_SIZE_MEDIUM 512
  #define JSON_SIZE_LARGE 1024
#endif

// 🔧 优化：常用字符串常量存储在PROGMEM中，避免重复创建
static const char MSG_SYSTEM_SLEEP[] PROGMEM = "[ERROR] 系统休眠中";
static const char MSG_NO_PATTERN[] PROGMEM = "[ERROR] 无图案数据";
static const char MSG_CONTROLLER_ERROR[] PROGMEM = "[ERROR] 控制器错误";
static const char MSG_SUCCESS[] PROGMEM = "[SUCCESS]";
static const char MSG_DRAWING_ACTIVE[] PROGMEM = "[INFO] 绘图进行中";

// 便捷访问宏
#define GET_MSG_SYSTEM_SLEEP() FPSTR(MSG_SYSTEM_SLEEP)
#define GET_MSG_NO_PATTERN() FPSTR(MSG_NO_PATTERN)
#define GET_MSG_CONTROLLER_ERROR() FPSTR(MSG_CONTROLLER_ERROR)

#endif // COMMAND_EXECUTOR_DEBUG_H
